package com.mengxuegu.springboot.controller;

import com.mengxuegu.springboot.mybatisplus.entities.Bill;
import com.mengxuegu.springboot.mybatisplus.entities.User;
import com.mengxuegu.springboot.mybatisplus.service.IBillService;
import com.mengxuegu.springboot.service.BizBillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class BillController {
    @Autowired
    IBillService billService;

    @Autowired
    BizBillService bizBillService;

    @GetMapping("/bill/{bid}")
    public Bill getBill(@PathVariable("bid") Integer bid) {
        Bill bill = billService.getBillByBid(bid);
        return bill;
    }

    @PostMapping("/bill")
    public Bill addBill(@RequestBody Bill bill) {
        int i = billService.addBill(bill);
        System.out.println(i);
        return bill;
    }

    @PostMapping("/billAndUser")
    public Bill billAndUser(@RequestBody Bill bill) {
        User user = new User();
        user.setRealName("李四");
        bizBillService.addUseBill(user, bill);
        return bill;
    }

    @PostMapping("/billUser")
    public Bill billUser(@RequestBody Bill bill) throws Exception{
        User user = new User();
        user.setRealName("李四");
        bizBillService.addUserAndBill(user, bill);
        return bill;
    }
}
